/**
 * Created by zp on 16/9/3.
 */
angular.module('starter.tabHome',[])
.controller('HomeCtrl',function($http,$scope,$state,$rootScope){

    $rootScope.badges = {
      carts: 3,
      contact: 0
    };
    var home={
      remarkSel:-1
    }

    $scope.datas=[1,2,3,4,5,6,7,8];


    $scope.test=function(mes){
      //fix all div height
      var height=document.getElementsByClassName("stand")[0].clientHeight;
      for(var i=0;i<document.getElementsByClassName("stand").length;i++){
        document.getElementsByClassName("stand")[i].style.height=height+2+"px";
      }
      //position child ele
      var str = ".strDiv:eq("+mes+")";
      var buttonDiv=document.getElementsByClassName("inButton")[mes];
      if(home.remarkSel!=-1){
        if(home.remarkSel==mes){
          if(buttonDiv.style.display=='none'){
            scrollTop(mes);
          }else{
            scrollBottom(mes);
          }
        }else{
          if(buttonDiv.style.display=='none'){
            scrollTop(mes);
          }else{
            scrollBottom(mes);
          }
          home.remarkSel=mes;
        }
      }else{
        home.remarkSel=mes;
        scrollTop(mes);
      }
    }

    function scrollTop(indexDiv){
      var str = ".strDiv:eq("+indexDiv+")";
      var buttonDiv=document.getElementsByClassName("inButton")[indexDiv];
      $(str).animate({
        marginTop:"-50px"
      },800);
      setTimeout(buttonDiv.style.display='',800);
    }

    function scrollBottom(indexDiv){
      var str = ".strDiv:eq("+indexDiv+")";
      var buttonDiv=document.getElementsByClassName("inButton")[indexDiv];
      $(str).animate({
        marginTop:"0px"
      },800);
      setTimeout(buttonDiv.style.display='none',800);
    }

    $scope.goAdd=function(){
      console.log("add");
      $state.go('tab.login');
      //$state.go('tab.register');
      //$state.go('tab.reset-password');
      //$state.go('tab.create-new-password');
    }

    $scope.goLogin = function(){
      $state.go("tab.register");
    }
  })
